static char *opt_subject;
static char *opt_body;
static char *opt_parent;
+static gboolean opt_orphan;
static char *opt_branch;
static char *opt_statoverride_file;
static char **opt_metadata_strings;
{ "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject", "SUBJECT" },
{ "body", 'm', 0, G_OPTION_ARG_STRING, &opt_body, "Full description", "BODY" },
{ "branch", 'b', 0, G_OPTION_ARG_STRING, &opt_branch, "Branch", "BRANCH" },
+ { "orphan", 0, 0, G_OPTION_ARG_NONE, &opt_orphan, "Create a commit without writing a ref", NULL },
{ "tree", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_trees, "Overlay the given argument as a tree", "dir=PATH or tar=TARFILE or ref=COMMIT" },
{ "add-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_strings, "Add a key/value pair to metadata", "KEY=VALUE" },
{ "add-detached-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_detached_metadata_strings, "Add a key/value pair to detached metadata", "KEY=VALUE" },
goto out;
}
- if (!opt_branch)
+ if (!(opt_branch || opt_orphan))
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "A branch must be specified with --branch");
+ "A branch must be specified with --branch, or use --orphan");
goto out;
}
parent = g_strdup (opt_parent);
}
}
- else
+ else if (!opt_orphan)
{
if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error))
goto out;
}
- if (!opt_subject && !opt_body)
+ if (!opt_subject && !opt_body && !opt_orphan)
{
if (!commit_editor (repo, opt_branch, &opt_subject, &opt_body, cancellable, error))
goto out;
}
}
- ostree_repo_transaction_set_ref (repo, NULL, opt_branch, commit_checksum);
+ if (opt_branch)
+ ostree_repo_transaction_set_ref (repo, NULL, opt_branch, commit_checksum);
+ else
+ g_assert (opt_orphan);
if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error))
goto out;
set -euo pipefail
-echo "1..52"
+echo "1..53"
$OSTREE checkout test2 checkout-test2
echo "ok checkout"
assert_streq $($OSTREE log test2-custom-parent |grep '^commit' | wc -l) "3"
echo "ok commit custom parent"
+cd ${test_tmpdir}
+orphaned_rev=$($OSTREE commit --orphan -s '' $test_tmpdir/checkout-test2-4)
+$OSTREE ls ${orphaned_rev} >/dev/null
+$OSTREE prune --refs-only
+if $OSTREE ls ${orphaned_rev} 2>err.txt; then
+ assert_not_reached "Found orphaned commit"
+fi
+assert_file_has_content err.txt "No such metadata object"
+echo "ok commit orphaned"
+
cd ${test_tmpdir}
$OSTREE diff test2^ test2 > diff-test2
assert_file_has_content diff-test2 'D */a/5'